<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改规费记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="padding: 20px" method="post" id="feesForm" >
    <%--隐藏域 接收父页面传值--%>
    <input type="text" id="tempCarid" hidden="hidden">
    <input type="text" id="tempBtypeid"hidden="hidden" >
    <input type="text" id="tempID" name="feesid" hidden="hidden">


    <div class="layui-form-item">
        <label class="layui-form-label">车辆</label>
        <div class="layui-input-block">
            <input type="text" id="carname" name="carname" readonly required  lay-verify="required" autocomplete="off" class="layui-input">
            <input type="text" id="carid" name="car.carid" required hidden lay-verify="required" autocomplete="off">

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">驾驶员</label>
        <div class="layui-input-block">
            <input type="text" name="dirver.drivername" readonly id="drivername" class="layui-input">
            <input type="text" hidden="hidden" name="dirver.driverid" id="driverid">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">费用名称</label>
        <div class="layui-input-block">
            <input type="text" id="feesname" name="feesname" required  lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">金额</label>
        <div class="layui-input-block">
            <input type="text" id="feesprice" name="feesprice" required  lay-verify="required" placeholder="请输入金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">费用产生时间:</label>
        <div class="layui-input-block">
            <input type="date" id="feestime" name="feestime" required  lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">收款单位</label>
        <div class="layui-input-block">
            <select id="btype"  lay-verify="required"  name="btype.btypeid">
                <option value=""></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="feesUpdate" id="addBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/layui/layui/layui.js"></script>
<script>

    layui.use(['form','layer','laydate','table','laytpl','upload'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table,
            upload=layui.upload;


        //得到驾驶员
            var carid=$("#tempCarid").val();
            $.ajax({
                url:"/car/car",
                data:{carid:carid},
                success:function (res) {
                    $("#drivername").val(res.data.driver.dirvername)
                    $("#driverid").val(res.data.driver.driverid);

                    console.log($("#driverid").val())
                }
            })


        //获取car数据
        $.ajax({
            url:"/car/allcar",
            success:function (res) {
                var tempCarid=$("#tempCarid").val();

                for(var i=0;i<res.data.length;i++){
                    if(tempCarid==res.data[i].carid){
                        $("#carname").val(res.data[i].carplate)
                        $("#carid").val(res.data[i].carid)
                    }

                }
                form.render('select');
            }
        });
        //获取btype数据
        $.ajax({
            url:"/btype/allBtype",
            success:function (res) {
                var tempBtypeid=$("#tempBtypeid").val();
                for(var i=0;i<res.data.length;i++){
                    var op=$("<option></option>");
                    op.attr('value',res.data[i].btypeid);
                    op.append(res.data[i].btypename);
                    if(res.data[i].btypeid==tempBtypeid){
                        op.attr("selected","selected");
                    }
                    $("#btype").append(op);
                }
                form.render('select');
            }
        });

        //提交表单
        form.on("submit(feesUpdate)",function(data) {
            $.ajax({
                type: "post",
                url: "/feesRecord/updateFeesRecord",
                data:$('#feesForm').serialize(),
                success: function (res) {
                  layui.layer.msg(res.msg)
                }
            })
            //点击提交后关闭悬浮窗
            setTimeout(function () {
                window.parent.location.reload()
            },1000)
            return false;
        })


    });
</script>
</body>
</html>